<template>
	<view class="content">
		<view class="menu-item">
			<view class="tab-item" :class="tabActive==1?'active':''" @click="bindActive(1)">按机构查看</view>
			<view class="tab-item" :class="tabActive==2?'active':''" @click="bindActive(2)">按时间查看</view>
		</view>
		<template v-if="infoList.length>0&&tabActive==1">
			<view class="info-block">
				<view class="info-item" v-for="(item,index) in infoList" :key="item.id"
					@click="navigate('/pages/supervise/secretary_detail?id='+item.id)">
					<view class="name-block">
						<view class="name">{{item.name}}</view>
						<view class="iconfont icon-youjiantou"></view>
					</view>
					<view class="title-item">
						<view class="name" v-if="item.list">{{item.list.duties}}:{{item.list.name}}</view>
					</view>
					<view class="time-item" v-if="item.list">
						<view v-for="(item1,index1) in item.list.report" :key="item1.id" class="one">
							<view class="onedot"></view>
							<view class="oneline"></view>
							<view class="onemain">
								<view style="display: flex;flex-direction: row;align-items: center;">
									<view class="onemaintitle">{{item1.createTime}}</view>
									<view class="onemaintitle" v-if="item1.time==1" style="margin-left: 15rpx;">上午
									</view>
									<view class="onemaintitle" v-else-if="item1.time==2" style="margin-left: 15rpx;">下午
									</view>
									<view class="onemaintitle" style="margin-left: 15rpx;" v-if="item1.location">
										{{item1.location}}
									</view>
								</view>
								<view class="onemaincon">{{item1.report}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</template>
		<view v-else style="text-align: center;">暂无数据</view>
		<template v-if="tabActive==2">
			<view class="table-box">
				<view class="select-item">
					<view class="form-text">动态时间：</view>
					<picker mode="date" class="form-ctrl" fields="day" :end="end" :value="workTimeStart"
						@change="bindStart">
						<view class="uni-input">{{workTimeStart}}
							<view class="iconfont icon-riqixuanze"></view>
						</view>

					</picker>
				</view>
				<template v-if="list.length>0">
					<table class="table">
						<tr class="top-item">
							<th style="width: 16%;text-align: center;">姓名</th>
							<th style="width: 20%;">上午</th>
							<th style="width: 20%;">地址</th>
							<th style="width: 20%;">下午</th>
							<th style="width: 20%;">地址</th>
						</tr>
						<tr v-for="(item,index) in list" :key="item.id" class="tab-list">
							<td style="width: 16%; text-align: center;color: #087DFF;" class="item">{{item.name}}</td>
							<td style="width: 21%;" class="item">{{item.morningText?item.morningText:'暂无'}}</td>
							<td style="width: 21%;" class="item">{{item.morningLocation?item.morningLocation:'暂无'}}</td>
							<td style="width: 21%;" class="item">{{item.afternoonText?item.afternoonText:'暂无'}}</td>
							<td style="width: 21%;" class="item">{{item.afternoonLocation?item.afternoonLocation:'暂无'}}
							</td>
						</tr>
					</table>
				</template>
				<view v-else style="text-align: center;">暂无数据</view>
			</view>
		</template>
	</view>
</template>

<script>
	import {
		getSelectListApi,
		getAllListApi
	} from '@/api/supervise.js'
	import {
		getCurrentTime,
		getPickerIndex
	} from '@/util/util';
	export default {
		data() {
			return {
				infoList: [],
				name: '',
				tabActive: 1,
				list: [],
				end: getCurrentTime('d'),
				workTimeStart: getCurrentTime('d'),

			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			bindActive(index) {
				this.tabActive = index
				if (this.tabActive == 1) {
					this.getList()
				} else {
					this.getSelectList()
				}
				this.workTimeStart = getCurrentTime('d')
			},
			bindStart(e) {
				this.workTimeStart = e.detail.value
				this.getSelectList()
			},
			getList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getSelectListApi({
					name: this.name
				}).then(res => {
					uni.hideLoading()
					this.infoList = res.list || []
				}).catch(() => {
					uni.hideLoading()
				})
			},
			getSelectList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getAllListApi({
					name: this.name,
					type: this.tabActive,
					startTime: this.workTimeStart
				}).then(res => {
					uni.hideLoading()
					this.list = res.reportModel || [];
				}).catch(() => {
					uni.hideLoading()
				})
			}
		},
		onLoad() {
			this.getList()
		},
		onShow() {
			this.workTimeStart = getCurrentTime('d')
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F5F5F5;
		width: 100%;


		.menu-item {
			width: 100%;
			height: 200rpx;
			background-color: #157EFE;
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			color: #fff;

			.tab-item {
				margin-top: 30rpx;
				height: 60rpx;
				font-size: 30rpx;
			}

			.tab-item.active {
				font-size: 34rpx;
				font-weight: bold;
				height: 60rpx;
				border-bottom: 6rpx solid #fff;
			}
		}


		.info-block {
			display: flex;
			flex-direction: column;
			height: auto;
			position: relative;
			background-color: #F5F9FC;
			margin-top: -100rpx;
			border-radius: 30rpx;
			padding: 30rpx;
			min-height: 100vh;

			.info-item {
				min-height: 140rpx;
				height: auto;
				box-shadow: 0 0 10px 0 #dedede;
				background: #fff;
				display: flex;
				flex-direction: column;
				justify-content: center;
				border-radius: 20rpx;
				padding: 30rpx;
				margin-bottom: 30rpx;

				.name-block {
					width: 100%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

					.name {
						font-weight: bold;
						font-size: 34rpx;
					}

					.iconfont {
						color: #CBCBCB;
					}
				}

				.title-item {
					width: 100%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					margin-top: 20rpx;

					.name {
						width: 100%;
						font-weight: bold;
						font-size: 30rpx;
					}

					.time {
						font-size: 28rpx;
						color: $uni-color-primary;
					}
				}


				.time-item.fewer {
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
					overflow: hidden;
					display: none;
				}

				.time-item {
					background: #F8F8F8;
					margin-top: 20rpx;
					padding: 20rpx;
					border-radius: 20rpx;

					.one {
						position: relative;
						padding-bottom: 10rpx;

						.onedot {
							left: -2rpx;
							width: 24rpx;
							height: 24rpx;
							position: absolute;
							//background-color: #4C7FE2;
							border: 1px solid #4C7FE2;
							border-radius: 50%;
							display: flex;
							justify-content: center;
							align-items: center;
							z-index: 1;
						}

						.oneline {
							position: absolute;
							left: 10rpx;
							height: calc(100% - 24rpx);
							border-left: 1px solid #1254F1;
							margin-top: 24rpx;
						}

						.onemain {
							position: relative;
							padding-left: 56rpx;
							top: -6rpx;
						}

						.onemaintitle {
							margin-bottom: 16rpx;
							padding-top: 8rpx;
							line-height: 1;
							font-size: 28rpx;
							color: #303133;
						}

						.onemaincon {
							color: #303133;
							background-color: #DFE8F9;
							padding: 20rpx;
							font-size: 28rpx;
							line-height: 60rpx;
						}
					}
				}
			}
		}

		.table-box {
			display: flex;
			flex-direction: column;
			height: auto;
			position: relative;
			background-color: #F5F9FC;
			margin-top: -140rpx;
			border-radius: 30rpx;
			min-height: 100vh;

			.select-item {
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				margin: 20rpx auto 30rpx auto;

				.form-text {
					font-size: 30rpx;
				}

				.form-ctrl {
					padding: 10rpx 20rpx;
					background-color: #E5E5E5;
					border-radius: 30rpx;
					display: flex;
					flex-direction: row;
					align-items: center;

					.uni-input {
						display: flex;
						flex-direction: row;
						align-items: center;
						font-size: 30rpx;

						.iconfont {
							font-size: 30rpx;
							margin-left: 30rpx;
							margin-right: 10rpx;
						}
					}

				}
			}

			.table {
				background-color: #fff;
				border-radius: 20rpx;

				.top-item {
					background-color: #3C91EF;
					display: flex;
					flex-direction: row;
					height: 90rpx;
					align-items: center;
					color: #fff;
					text-align: center;
					//font-weight: bold;
				}

				.tab-list {
					display: flex;
					padding-bottom: 20rpx;
					padding-top: 20rpx;
					background-color: #fff;

					.item {
						font-size: 28rpx;
					}
				}

				.tab-list:nth-child(2n) {
					background-color: #F4F9F8;
				}
			}
		}
	}
</style>